

import { Withdrawals } from '../withdrawals/withdrawals-model.js';
import { My } from '../my/my-model.js';
import { Agent } from '../agent/agent-model.js';
import { Config } from '../config/config-model.js';
var withdrawals = new Withdrawals();
var agent = new Agent();

var my = new My();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingHidden: false,
    curCountry:0,
    bankArr: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that._loadData();
  },
  _loadData: function (options) {
    var that = this
    //页面加载完毕查询是否有银行卡信息
    withdrawals.selBankValue((data) => {
      // var bkArr = new Array();
      this.data.bankArr = data;

      for (var i in data) {
        data[i]['bank_name'] += ' [尾号：' + data[i]['bank_number'].slice(-4) + ']'

      }

      if (data.length == 0) {
        this.data.isBank = 0
      } else {
        this.data.isBank = 1

      }
      // console.log(data)

      // console.log(data.map(i => i.bank_name))

      this.setData({
        isBank: this.data.isBank,
        accounts: data,
        c: data.map(i => i.bank_name),


      })
    })
    //查询已购车信息 where条件3,余额显示
    agent.selToCraData((data) => {
      var income;

      if (data.length == 0) {
        this.data.toCraData = 0
      } else {

        for (var i in data) {


          this.data.toCraData = data[i]['income']
        }
      }
      this.setData({
        toCraData: this.data.toCraData,
      })

    })
  },
  //select 选中
  bindAccountChange: function (e) {
    console.log('picker account 发生选择改变，携带值为', e.detail.value);
    console.log(e)
    this.setData({
      curCountry: Number(e.detail.value)
    })
  },
  //挑战到bank添加页
  bankUrl: function () {
    wx.navigateTo({
      url: '../bank/bank'
    })
  },
  //提现
  toMonney: function (e) {
    let { accounts, curCountry } = this.data;
    
    var bankId=new Array()
    bankId['id'] = accounts[curCountry].id
    withdrawals.toMonneyRequest(bankId,(data)=>{
      console.log(data)

    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var page = getCurrentPages().pop();
    if (page == undefined || page == null) return;
    page._loadData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})